package com.link.base.tencent.corpwx.accounttag.controller;

import com.link.base.tencent.corpwx.accounttag.model.AccountTagItem;
import com.link.base.tencent.corpwx.accounttag.service.AccountTagItemService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户标签
 *
 * @author 欧阳振强
 * @date 2020-01-02 15:02:09.0
 */
@Controller
@RequestMapping("/link/corpwx/accountTagItem")
public class AccountTagItemController extends BasicController<AccountTagItem> {

    @Resource
    private AccountTagItemService accountTagItemService;

    @Override
    public BasicService<AccountTagItem> getBasicService() throws Exception {
        return accountTagItemService;
    }

    /**
     * 删除标签
     *
     * @author 欧阳振强
     * @date 2020/01/03
     */
    @PostMapping(value = "/delTagItemById", name = "删除标签")
    @ResponseBody
    public Map<String, Object> delTagGroupById(@JsonParam AccountTagItem record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            accountTagItemService.delTagItemById(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 同步标签到企业微信
     *
     * @author 欧阳振强
     * @date 2020/01/03
     */
    @PostMapping(value = "/syncTagItemToWx", name = "同步标签到企业微信")
    @ResponseBody
    public Map<String, Object> syncTagItemToWx(@JsonParam AccountTagItem record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            accountTagItemService.syncTagItemToWx(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}